/*
 * @lc app=leetcode id=476 lang=cpp
 *
 * [476] Number Complement
 */

// @lc code=start
class Solution {
public:
    int findComplement(int num) {
        int ans = 0;
        int i = 0;
        while (num != 1) {
            ans |= ((num & 1) ^ 1) <<i;
            i++;
            num >>= 1;

        }
        return ans ;
    }
};
// @lc code=end

